package com.bjsxt.controller;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.bjsxt.util.AliPhoneUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class AliyunController {

    @PostMapping("/phone")
    @ResponseBody
    public String phoneCode(String phonenumber) throws ClientException {

        AliPhoneUtil aliPhoneUtil = new AliPhoneUtil();
        //得到验证码
        aliPhoneUtil.setNewcode();
        String newCode = Integer.toString(aliPhoneUtil.getNewcode());
        SendSmsResponse sendSmsResponse = aliPhoneUtil.sendSms(phonenumber,newCode);
        System.out.println(sendSmsResponse);
        return sendSmsResponse.getCode();
    }

}
